﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class SystemTypeManageForm : System.Windows.Forms.Form
	{
		private void removeLatLevelNode()
		{
		}

		public SystemTypeManageForm(List<PipingSystemType> listPipingSystemType, List<MechanicalSystemType> listMechanicalSystemType, Document doc, UIApplication app, string type)
		{
			this.InitializeComponent();
			this.listPipingSystemType = listPipingSystemType;
			this.listMechanicalSystemType = listMechanicalSystemType;
			this.linePattern = SystemManageHelper.Get_LinePatternElement(doc);
			this.doc = doc;
			this.app = app;
			this.uidoc = app.ActiveUIDocument;
			this.type = type;
			this.button1.Image = Resources.AddNew16;
			this.button2.Image = Resources.modify16;
			this.button3.Image = Resources.delete16;
			this.buttonNewSystem.Image = Resources.AddNew16;
			this.buttonCorrect.Image = Resources.modify16;
			this.buttonDelete.Image = Resources.delete16;
			if (!File.Exists(SystemTypeManageForm.path))
			{
				File.Copy(Path.Combine(Product.DataLocation, "User\\YJKPipingSystemTypeSetInformation.xml"), SystemTypeManageForm.path, true);
			}
			base.CenterToScreen();
			this.startupType = Product.GetDisciplineValue();
		}

		private void InitalizeTreeNode()
		{
			this.treeView1.Nodes.Clear();
			this.tn0.Nodes.Clear();
			this.tnduct.Tag = "DuctSystem";
			this.tnpipe.Tag = "PipeSystem";
			List<string> list = new List<string>();
			foreach (PipingSystemType pipingSystemType in this.listPipingSystemType)
			{
				string pipeSystemTypeCH = AssistSystemType.GetPipeSystemTypeCH(pipingSystemType.SystemClassification.ToString());
				if (!list.Contains(pipeSystemTypeCH))
				{
					TreeNode treeNode = new TreeNode(pipeSystemTypeCH);
					treeNode.Tag = pipingSystemType.SystemClassification.ToString();
					this.tnpipe.Nodes.Add(treeNode);
					list.Add(pipeSystemTypeCH);
				}
			}
			list.Clear();
			foreach (MechanicalSystemType mechanicalSystemType in this.listMechanicalSystemType)
			{
				string ductSystemTypeCH = AssistSystemType.GetDuctSystemTypeCH(mechanicalSystemType.SystemClassification.ToString());
				if (!list.Contains(ductSystemTypeCH))
				{
					TreeNode treeNode2 = new TreeNode(ductSystemTypeCH);
					treeNode2.Tag = mechanicalSystemType.SystemClassification.ToString();
					this.tnduct.Nodes.Add(treeNode2);
					list.Add(ductSystemTypeCH);
				}
			}
			this.tn0.Nodes.Add(this.tnduct);
			this.tn0.Nodes.Add(this.tnpipe);
			this.treeView1.Nodes.Add(this.tn0);
			this.tn0.Expand();
		}

		private void insertNodeTotreeView(TreeNode treeNode1, systemTypeStruct sss)
		{
		}

		private void AddDataFromDocument()
		{
			SystemTypeManageForm.structList.Clear();
			SystemTypeManageForm.bigList.Clear();
			SystemTypeManageForm.structListMoRen.Clear();
			for (int i = 0; i < this.listPipingSystemType.Count; i++)
			{
				SystemTypeManageForm.SetPipingSystemSimple(this.listPipingSystemType[i]);
				systemTypeStruct systemTypeStruct = new systemTypeStruct();
				systemTypeStruct.PipingSystemType = AssistSystemType.GetPipeSystemTypeCH(this.listPipingSystemType[i].Name);
				systemTypeStruct.PipingSystemTypeAbb = this.listPipingSystemType[i].get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).AsString();
				systemTypeStruct.PipeSystemType = this.listPipingSystemType[i].SystemClassification.ToString();
				systemTypeStruct.Color = SystemManageHelper.getRGB(this.listPipingSystemType[i]);
				systemTypeStruct.LinePattern = SystemManageHelper.getLinePattern(this.listPipingSystemType[i], this.doc);
				systemTypeStruct.LineWeight = SystemManageHelper.getLineWeight(this.listPipingSystemType[i]);
				systemTypeStruct.SystemClass = this.GetSystemClassnew(this.listPipingSystemType[i].SystemClassification.ToString());
				SystemTypeManageForm.structList.Add(systemTypeStruct);
			}
			for (int j = 0; j < this.listMechanicalSystemType.Count; j++)
			{
				SystemTypeManageForm.SetMechanicalSystemSimple(this.listMechanicalSystemType[j]);
				systemTypeStruct systemTypeStruct2 = new systemTypeStruct();
				systemTypeStruct2.PipingSystemType = AssistSystemType.GetDuctSystemTypeCH(this.listMechanicalSystemType[j].Name);
				systemTypeStruct2.PipingSystemTypeAbb = this.listMechanicalSystemType[j].get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).AsString();
				systemTypeStruct2.PipeSystemType = this.listMechanicalSystemType[j].SystemClassification.ToString();
				systemTypeStruct2.Color = SystemManageHelper.getRGB(this.listMechanicalSystemType[j]);
				systemTypeStruct2.LinePattern = SystemManageHelper.getLinePattern(this.listMechanicalSystemType[j], this.doc);
				systemTypeStruct2.LineWeight = SystemManageHelper.getLineWeight(this.listMechanicalSystemType[j]);
				systemTypeStruct2.SystemClass = this.GetSystemClassnew(this.listMechanicalSystemType[j].SystemClassification.ToString());
				SystemTypeManageForm.structList.Add(systemTypeStruct2);
			}
			foreach (systemTypeStruct systemTypeStruct3 in SystemTypeManageForm.structList)
			{
				systemTypeStruct systemTypeStruct4 = new systemTypeStruct();
				systemTypeStruct4.PipingSystemType = systemTypeStruct3.PipingSystemType;
				systemTypeStruct4.PipingSystemTypeAbb = systemTypeStruct3.PipingSystemTypeAbb;
				systemTypeStruct4.PipeSystemType = systemTypeStruct3.PipeSystemType;
				systemTypeStruct4.Color = systemTypeStruct3.Color;
				systemTypeStruct4.LinePattern = systemTypeStruct3.LinePattern;
				systemTypeStruct4.LineWeight = systemTypeStruct3.LineWeight;
				systemTypeStruct4.SystemClass = systemTypeStruct3.SystemClass;
				SystemTypeManageForm.structListMoRen.Add(systemTypeStruct4);
			}
		}

		private void SystemTypeManageForm_Load(object sender, EventArgs e)
		{
			this.buttonCorrect.Visible = false;
			this.buttonDelete.Visible = true;
			this.InitalizeTreeNode();
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.HeaderText = "系统类型名称";
			dataGridViewTextBoxColumn.Width = 100;
			dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridView1.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn
			});
			dataGridViewTextBoxColumn.MinimumWidth = 100;
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn2.HeaderText = "缩写";
			dataGridViewTextBoxColumn2.Width = 60;
			dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridView1.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn2
			});
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn3.HeaderText = "线颜色";
			dataGridViewTextBoxColumn3.Width = 125;
			dataGridViewTextBoxColumn3.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridView1.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn3
			});
			dataGridViewTextBoxColumn3.ReadOnly = true;
			dataGridViewTextBoxColumn3.MinimumWidth = 125;
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn.HeaderText = "线型";
			dataGridViewComboBoxColumn.Width = 100;
			dataGridViewComboBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridView1.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn
			});
			dataGridViewComboBoxColumn.FlatStyle = FlatStyle.Popup;
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn2 = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn2.HeaderText = "线宽";
			dataGridViewComboBoxColumn2.Width = 56;
			dataGridViewComboBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridView1.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn2
			});
			dataGridViewComboBoxColumn2.FlatStyle = FlatStyle.Popup;
			foreach (LinePatternElement linePatternElement in SystemManageHelper.Get_LinePatternElement(this.doc))
			{
				dataGridViewComboBoxColumn.Items.AddRange(new object[]
				{
					linePatternElement.Name
				});
			}
			dataGridViewComboBoxColumn.Items.Add("默认");
			for (int i = 1; i < 17; i++)
			{
				dataGridViewComboBoxColumn2.Items.Add(i.ToString());
			}
			dataGridViewComboBoxColumn2.Items.Add("默认");
			this.dataGridView1.RowTemplate.Height = 22;
			this.dataGridView1.RowHeadersWidth = 30;
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn4 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn4.HeaderText = "类型";
			dataGridViewTextBoxColumn4.Width = 1;
			dataGridViewTextBoxColumn4.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridView1.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn4
			});
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn5 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn5.HeaderText = "系统类型";
			dataGridViewTextBoxColumn5.Width = 1;
			dataGridViewTextBoxColumn5.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.dataGridView1.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn5
			});
			this.dataGridView1.Columns[5].Visible = false;
			this.dataGridView1.Columns[6].Visible = false;
			SystemTypeManageForm.structList.Clear();
			SystemTypeManageForm.bigList.Clear();
			SystemTypeManageForm.structListMoRen.Clear();
			this.AddDataFromDocument();
			int count = this.listPipingSystemType.Count;
			if (File.Exists(SystemTypeManageForm.path))
			{
				SystemTypeManageForm.bigList = XML.readBig(SystemTypeManageForm.path, "systemTypeManage", this.startupType);
				this.listBox1.Items.Add("当前样式");
				using (List<bigStruct>.Enumerator enumerator2 = SystemTypeManageForm.bigList.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						bigStruct bigStruct = enumerator2.Current;
						if (bigStruct.style != "当前样式" && !this.listBox1.Items.Contains(bigStruct.style))
						{
							this.listBox1.Items.Add(bigStruct.style);
						}
					}
					goto IL_3BB;
				}
			}
			MessageBox.Show("记录信息被删除！");
			IL_3BB:
			this.listBox1.SelectedItem = "当前样式";
			SystemTypeManageForm.structList.Clear();
			this.dataGridView1.Rows.Clear();
			foreach (systemTypeStruct systemTypeStruct in SystemTypeManageForm.structListMoRen)
			{
				systemTypeStruct systemTypeStruct2 = new systemTypeStruct();
				systemTypeStruct2.PipingSystemType = systemTypeStruct.PipingSystemType;
				systemTypeStruct2.PipingSystemTypeAbb = systemTypeStruct.PipingSystemTypeAbb;
				systemTypeStruct2.PipeSystemType = systemTypeStruct.PipeSystemType;
				systemTypeStruct2.Color = systemTypeStruct.Color;
				systemTypeStruct2.LinePattern = systemTypeStruct.LinePattern;
				systemTypeStruct2.LineWeight = systemTypeStruct.LineWeight;
				systemTypeStruct2.SystemClass = systemTypeStruct.SystemClass;
				SystemTypeManageForm.structList.Add(systemTypeStruct2);
				object[] values = new object[]
				{
					systemTypeStruct.PipingSystemType,
					systemTypeStruct.PipingSystemTypeAbb,
					systemTypeStruct.Color,
					systemTypeStruct.LinePattern,
					systemTypeStruct.LineWeight,
					systemTypeStruct.SystemClass,
					systemTypeStruct2.PipeSystemType
				};
				this.dataGridView1.Rows.Add(values);
			}
			foreach (bigStruct bigStruct2 in SystemTypeManageForm.bigList)
			{
				if (bigStruct2.style == this.listBox1.SelectedItem.ToString())
				{
					new SystemManageHelper().SaveBigList(bigStruct2);
				}
				if (bigStruct2.style == "当前样式")
				{
					new SystemManageHelper().SaveBigList(bigStruct2);
				}
			}
			this.ColorInint();
			this.isValid = true;
			this.isUpdateBsStyle = true;
			this.removeLatLevelNode();
			this.treeView1.SelectedNode = this.tnduct;
			this.treeView1.SelectedNode = this.tn0;
		}

		private void deleteRevitNotHaveSystemType(systemTypeStruct[] systemStruts)
		{
			int num = systemStruts.Count<systemTypeStruct>();
			if (num > 0)
			{
				for (int i = 0; i < num; i++)
				{
					if (!SystemTypeManageForm.structListMoRen.Contains(systemStruts.ElementAt(i)))
					{
						systemStruts.ToList<systemTypeStruct>().RemoveAt(i);
						i--;
					}
				}
			}
		}

		private ElementId getLinePatternIdUseName(string name)
		{
			return LinePatternElement.GetLinePatternElementByName(this.doc, name).Id;
		}

		public static void SetMechanicalSystemSimple(MechanicalSystemType mst)
		{
			string text = "";
			string name = mst.Name;
			if (!(name == "送风"))
			{
				if (!(name == "回风"))
				{
					if (name == "排风")
					{
						text = "PF";
					}
				}
				else
				{
					text = "HF";
				}
			}
			else
			{
				text = "SF";
			}
			Parameter parameter = mst.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM);
			if (parameter.AsString() == "")
			{
				parameter.Set(text);
			}
		}

		public static void SetPipingSystemSimple(PipingSystemType pst)
		{
			string text = "";
			string name = pst.Name;
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(name);
			if (num <= 2187079225u)
			{
				if (num <= 1204270209u)
				{
					if (num != 806828493u)
					{
						if (num == 1204270209u)
						{
							if (name == "其他消防系统")
							{
								text = "QTXFXT";
							}
						}
					}
					else if (name == "其他")
					{
						text = "QT";
					}
				}
				else if (num != 1229342730u)
				{
					if (num != 1366947159u)
					{
						if (num == 2187079225u)
						{
							if (name == "循环供水")
							{
								text = "XHGS";
							}
						}
					}
					else if (name == "通风孔")
					{
						text = "TFK";
					}
				}
				else if (name == "家用热水")
				{
					text = "JYRS";
				}
			}
			else if (num <= 3675399567u)
			{
				if (num != 2563745786u)
				{
					if (num != 2731895364u)
					{
						if (num == 3675399567u)
						{
							if (name == "预作用消防系统")
							{
								text = "YZYXFXT";
							}
						}
					}
					else if (name == "循环回水")
					{
						text = "XHHS";
					}
				}
				else if (name == "干式消防系统")
				{
					text = "GSXF";
				}
			}
			else if (num != 3914730892u)
			{
				if (num != 4079822120u)
				{
					if (num == 4199473803u)
					{
						if (name == "湿式消防系统")
						{
							text = "SSXF";
						}
					}
				}
				else if (name == "家用冷水")
				{
					text = "JYLS";
				}
			}
			else if (name == "卫生设备")
			{
				text = "WSSB";
			}
			Parameter parameter = pst.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM);
			if (parameter.AsString() == "")
			{
				parameter.Set(text);
			}
		}

		private string GetSystemClassnew(string pipeSystemType)
		{
			uint num = YArchitech.Revit.PrivateImplementationDetails.ComputeStringHash(pipeSystemType);
			if (num <= 2017692542u)
			{
				if (num <= 1524890971u)
				{
					if (num <= 514019971u)
					{
						if (num != 81264407u)
						{
							if (num == 514019971u)
							{
								if (pipeSystemType == "ReturnHydronic")
								{
									return "管道系统";
								}
							}
						}
						else if (pipeSystemType == "ExhaustAir")
						{
							return "风管系统";
						}
					}
					else if (num != 842668758u)
					{
						if (num == 1524890971u)
						{
							if (pipeSystemType == "DomesticHotWater")
							{
								return "管道系统";
							}
						}
					}
					else if (pipeSystemType == "SupplyHydronic")
					{
						return "管道系统";
					}
				}
				else if (num <= 1698412355u)
				{
					if (num != 1678934222u)
					{
						if (num == 1698412355u)
						{
							if (pipeSystemType == "FireProtectPreaction")
							{
								return "管道系统";
							}
						}
					}
					else if (pipeSystemType == "Global")
					{
						return "全局";
					}
				}
				else if (num != 1807552510u)
				{
					if (num != 2003677185u)
					{
						if (num == 2017692542u)
						{
							if (pipeSystemType == "Vent")
							{
								return "管道系统";
							}
						}
					}
					else if (pipeSystemType == "FireProtectDry")
					{
						return "管道系统";
					}
				}
				else if (pipeSystemType == "Sanitary")
				{
					return "管道系统";
				}
			}
			else if (num <= 3017983553u)
			{
				if (num <= 2482186404u)
				{
					if (num != 2382714854u)
					{
						if (num == 2482186404u)
						{
							if (pipeSystemType == "FireProtectWet")
							{
								return "管道系统";
							}
						}
					}
					else if (pipeSystemType == "DomesticColdWater")
					{
						return "管道系统";
					}
				}
				else if (num != 2603360416u)
				{
					if (num == 3017983553u)
					{
						if (pipeSystemType == "ReturnAir")
						{
							return "风管系统";
						}
					}
				}
				else if (pipeSystemType == "Fitting")
				{
					return "管件";
				}
			}
			else if (num <= 3891676362u)
			{
				if (num != 3313474090u)
				{
					if (num == 3891676362u)
					{
						if (pipeSystemType == "UndefinedSystemType")
						{
							return "管道系统";
						}
					}
				}
				else if (pipeSystemType == "FireProtectOther")
				{
					return "管道系统";
				}
			}
			else if (num != 3995932714u)
			{
				if (num != 4199155463u)
				{
					if (num == 4225100969u)
					{
						if (pipeSystemType == "OtherPipe")
						{
							return "管道系统";
						}
					}
				}
				else if (pipeSystemType == "OtherAir")
				{
					return "风管系统";
				}
			}
			else if (pipeSystemType == "SupplyAir")
			{
				return "风管系统";
			}
			return "管道系统";
		}

		private string getSystemClass(string pipingSystemType)
		{
			string result = "其他";
			systemTypeStruct[] collection = XML.readstruct(SystemTypeManageForm.path, "systemTypeManage", "当前样式", "空调风系统");
			systemTypeStruct[] collection2 = XML.readstruct(SystemTypeManageForm.path, "systemTypeManage", "当前样式", "空调水系统");
			systemTypeStruct[] collection3 = XML.readstruct(SystemTypeManageForm.path, "systemTypeManage", "当前样式", "给排水系统");
			systemTypeStruct[] collection4 = XML.readstruct(SystemTypeManageForm.path, "systemTypeManage", "当前样式", "采暖系统");
			systemTypeStruct[] collection5 = XML.readstruct(SystemTypeManageForm.path, "systemTypeManage", "当前样式", "消防系统");
			systemTypeStruct[] collection6 = XML.readstruct(SystemTypeManageForm.path, "systemTypeManage", "当前样式", "其他");
			List<systemTypeStruct> list = new List<systemTypeStruct>();
			list.AddRange(collection);
			list.AddRange(collection2);
			list.AddRange(collection3);
			list.AddRange(collection4);
			list.AddRange(collection5);
			list.AddRange(collection6);
			foreach (systemTypeStruct systemTypeStruct in list)
			{
				if (systemTypeStruct.PipingSystemType == pipingSystemType)
				{
					result = systemTypeStruct.SystemClass;
				}
			}
			return result;
		}

		private void buttonInput_Click(object sender, EventArgs e)
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = " xml files(*.xml)|*.xml|All files(*.*)|*.*";
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				try
				{
					List<bigStruct> newBig = new List<bigStruct>();
					newBig = XML.readBig(openFileDialog.FileName, "systemTypeManage", this.intImportExport);
					new AddStyle(this.listBox1, "导入系统管理样式", newBig, this.dataGridView1).ShowDialog();
				}
				catch
				{
					YJKMessageBox.Show("请导入正确的数据文件！");
				}
				this.treeView1.SelectedNode = this.tn0;
			}
		}

		private void buttonOutput_Click(object sender, EventArgs e)
		{
			this.SaveFileDialog(this.listBox1.SelectedItem.ToString().Trim());
		}

		private void SaveFileDialog(string fileName)
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.Filter = " xml files(*.xml)|*.xml|All files(*.*)|*.*";
			saveFileDialog.FileName = fileName;
			saveFileDialog.FilterIndex = 1;
			saveFileDialog.RestoreDirectory = true;
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				string text = saveFileDialog.FileName.ToString();
				string text2 = text.Substring(text.LastIndexOf("\\") + 1);
				text.Substring(0, text.LastIndexOf("\\"));
                //DateTime.Now.ToString("yyyyMMdd") + text2;
				saveFileDialog.FileName.Insert(1, "dameng");
				foreach (bigStruct bigStruct in SystemTypeManageForm.bigList)
				{
					if (bigStruct.style == this.listBox1.SelectedItem.ToString())
					{
						IEnumerable<systemTypeStruct> source = from c in SystemTypeManageForm.structList
						where c.SystemClass == "空调风系统"
						select c;
						bigStruct.HVACDuctsystemStruct = source.ToArray<systemTypeStruct>();
						IEnumerable<systemTypeStruct> source2 = from c in SystemTypeManageForm.structList
						where c.SystemClass == "空调水系统"
						select c;
						bigStruct.HVACWatersystemStruct = source2.ToArray<systemTypeStruct>();
						IEnumerable<systemTypeStruct> source3 = from c in SystemTypeManageForm.structList
						where c.SystemClass == "给排水系统"
						select c;
						bigStruct.WatersystemStruct = source3.ToArray<systemTypeStruct>();
						IEnumerable<systemTypeStruct> source4 = from c in SystemTypeManageForm.structList
						where c.SystemClass == "采暖系统"
						select c;
						bigStruct.CNsystemStruct = source4.ToArray<systemTypeStruct>();
						IEnumerable<systemTypeStruct> source5 = from c in SystemTypeManageForm.structList
						where c.SystemClass == "消防系统"
						select c;
						bigStruct.FiresystemStruct = source5.ToArray<systemTypeStruct>();
						IEnumerable<systemTypeStruct> source6 = from c in SystemTypeManageForm.structList
						where c.SystemClass == "其他"
						select c;
						bigStruct.QITA = source6.ToArray<systemTypeStruct>();
						IEnumerable<systemTypeStruct> source7 = from c in SystemTypeManageForm.structList
						where c.SystemClass == "风管系统"
						select c;
						bigStruct.DuctSystemStruct = source7.ToArray<systemTypeStruct>();
						IEnumerable<systemTypeStruct> source8 = from c in SystemTypeManageForm.structList
						where c.SystemClass == "管道系统"
						select c;
						bigStruct.PipeSystemStruct = source8.ToArray<systemTypeStruct>();
					}
				}
				XML.deleteNext(text, "systemTypeManage", this.intImportExport, "");
				foreach (bigStruct bigStruct2 in SystemTypeManageForm.bigList)
				{
					if (bigStruct2.style == this.listBox1.SelectedItem.ToString().Trim())
					{
						string style = bigStruct2.style;
						bigStruct2.style = text2.Split(new char[]
						{
							'.'
						}).ElementAt(0);
						List<systemTypeStruct> list = new List<systemTypeStruct>();
						list.AddRange(bigStruct2.DuctSystemStruct);
						list.AddRange(bigStruct2.PipeSystemStruct);
						XML.writeInfoToXML(text, bigStruct2.style, "systemTypeManage", list, this.intImportExport);
						bigStruct2.style = style;
					}
				}
				YJKMessageBox.Show("导出成功！");
			}
		}

		private void createOrUpdataSystemClass(string systemName, string systemType, string abbreviationName, string clor, string linePattern, string lineWitdh)
		{
			if (!this.IsHaveSystemType(systemName))
			{
				try
				{
					MEPSystemClassification mepsystemClassification = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetPipeSystemTypeUS(systemType), true);
					MechanicalSystemType mechanicalSystemType = MechanicalSystemType.Create(this.doc, mepsystemClassification, systemName);
					mechanicalSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(abbreviationName);
					if (clor != "默认")
					{
                        mechanicalSystemType.LineColor = new Autodesk.Revit.DB.Color((byte)int.Parse(clor.Split(new char[]
						{
							' '
						}).ElementAt(0)), (byte)int.Parse(clor.Split(new char[]
						{
							' '
						}).ElementAt(1)), (byte)int.Parse(clor.Split(new char[]
						{
							' '
						}).ElementAt(2)));
					}
					if (linePattern != "默认")
					{
						mechanicalSystemType.LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, linePattern).Id;
					}
					if (lineWitdh != "默认")
					{
						mechanicalSystemType.LineWeight = int.Parse(lineWitdh);
					}
					return;
				}
				catch
				{
					MEPSystemClassification mepsystemClassification2 = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetDuctSystemTypeUS(systemName), true);
					PipingSystemType pipingSystemType = PipingSystemType.Create(this.doc, mepsystemClassification2, systemName);
					pipingSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(abbreviationName);
					if (clor != "默认")
					{
                        pipingSystemType.LineColor = new Autodesk.Revit.DB.Color((byte)int.Parse(clor.Split(new char[]
						{
							' '
						}).ElementAt(0)), (byte)int.Parse(clor.Split(new char[]
						{
							' '
						}).ElementAt(1)), (byte)int.Parse(clor.Split(new char[]
						{
							' '
						}).ElementAt(2)));
					}
					if (linePattern != "默认")
					{
						pipingSystemType.LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, linePattern).Id;
					}
					if (lineWitdh != "默认")
					{
						pipingSystemType.LineWeight = int.Parse(lineWitdh);
					}
					return;
				}
			}
			AssistSystemType.getPipingSystemTypeAccordName(systemName, this.listPipingSystemType);
		}

		private bool IsHaveSystemType(string systemName)
		{
			bool result = false;
			using (List<PipingSystemType>.Enumerator enumerator = this.listPipingSystemType.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.Name == systemName)
					{
						result = true;
					}
				}
			}
			using (List<MechanicalSystemType>.Enumerator enumerator2 = this.listMechanicalSystemType.GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					if (enumerator2.Current.Name == systemName)
					{
						result = true;
					}
				}
			}
			return result;
		}

		private void drawPipe(int i)
		{
			this.listPipingSystemType[i].Name = this.dataGridView1.Rows[i].Cells[0].Value.ToString();
			this.listPipingSystemType[i].get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(this.dataGridView1.Rows[i].Cells[1].Value.ToString());
			if (this.dataGridView1.Rows[i].Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
				this.listPipingSystemType[i].LineColor = revirColor;
				new AssistSystemType();
			}
			if (this.dataGridView1.Rows[i].Cells[3].Value != null && this.dataGridView1.Rows[i].Cells[3].Value.ToString() != "默认")
			{
				this.listPipingSystemType[i].LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, this.dataGridView1.Rows[i].Cells[3].Value.ToString()).Id;
			}
			else
			{
				this.listPipingSystemType[i].LinePatternId = ElementId.InvalidElementId;
			}
			if (this.dataGridView1.Rows[i].Cells[4].Value.ToString() != "默认")
			{
				this.listPipingSystemType[i].LineWeight = int.Parse(this.dataGridView1.Rows[i].Cells[4].Value.ToString());
				return;
			}
			this.listPipingSystemType[i].LineWeight = 5;
		}

		private void drawDuct(int i, int c)
		{
			this.listMechanicalSystemType[c].Name = this.dataGridView1.Rows[i].Cells[0].Value.ToString();
			this.listMechanicalSystemType[c].get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(this.dataGridView1.Rows[i].Cells[1].Value.ToString());
			if (this.dataGridView1.Rows[i].Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
				this.listMechanicalSystemType[c].LineColor = revirColor;
				new AssistSystemType();
			}
			if (this.dataGridView1.Rows[i].Cells[3].Value != null && this.dataGridView1.Rows[i].Cells[3].Value.ToString() != "默认")
			{
				this.listMechanicalSystemType[c].LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, this.dataGridView1.Rows[i].Cells[3].Value.ToString()).Id;
			}
			else
			{
				this.listMechanicalSystemType[c].LinePatternId = ElementId.InvalidElementId;
			}
			if (this.dataGridView1.Rows[i].Cells[4].Value.ToString() != "默认")
			{
				this.listMechanicalSystemType[c].LineWeight = int.Parse(this.dataGridView1.Rows[i].Cells[4].Value.ToString());
				return;
			}
			this.listMechanicalSystemType[c].LineWeight = 5;
		}

		private void newDrawPipe(int i, PipingSystemType pst)
		{
			if (this.dataGridView1.Rows[i].Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
				pst.LineColor = revirColor;
				new AssistSystemType();
			}
			if (this.dataGridView1.Rows[i].Cells[3].Value != null && this.dataGridView1.Rows[i].Cells[3].Value.ToString() != "默认")
			{
				pst.LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, this.dataGridView1.Rows[i].Cells[3].Value.ToString()).Id;
			}
			else
			{
				pst.LinePatternId = ElementId.InvalidElementId;
			}
			if (this.dataGridView1.Rows[i].Cells[4].Value.ToString() != "默认")
			{
				pst.LineWeight = int.Parse(this.dataGridView1.Rows[i].Cells[4].Value.ToString());
				return;
			}
			pst.LineWeight = 5;
		}

		private void newDrawDuct(int i, MechanicalSystemType mst)
		{
			if (this.dataGridView1.Rows[i].Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(this.dataGridView1.Rows[i].Cells[2].Value.ToString());
				mst.LineColor = revirColor;
				new AssistSystemType();
			}
			if (this.dataGridView1.Rows[i].Cells[3].Value != null && this.dataGridView1.Rows[i].Cells[3].Value.ToString() != "默认")
			{
				mst.LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, this.dataGridView1.Rows[i].Cells[3].Value.ToString()).Id;
			}
			else
			{
				mst.LinePatternId = ElementId.InvalidElementId;
			}
			if (this.dataGridView1.Rows[i].Cells[4].Value.ToString() != "默认")
			{
				mst.LineWeight = int.Parse(this.dataGridView1.Rows[i].Cells[4].Value.ToString());
				return;
			}
			mst.LineWeight = 5;
		}

		private void DrawPipe(int i, DataGridViewRow dr)
		{
			this.listPipingSystemType[i].Name = dr.Cells[0].Value.ToString();
			this.listPipingSystemType[i].get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(dr.Cells[1].Value.ToString());
			if (dr.Cells[3].Value != null && dr.Cells[3].Value.ToString() != "默认")
			{
				this.listPipingSystemType[i].LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, dr.Cells[3].Value.ToString()).Id;
			}
			else
			{
				this.listPipingSystemType[i].LinePatternId = ElementId.InvalidElementId;
			}
			if (dr.Cells[4].Value.ToString() != "默认")
			{
				this.listPipingSystemType[i].LineWeight = int.Parse(dr.Cells[4].Value.ToString());
			}
			else
			{
				this.listPipingSystemType[i].LineWeight = 5;
			}
			if (dr.Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(dr.Cells[2].Value.ToString());
				this.listPipingSystemType[i].LineColor = revirColor;
				new AssistSystemType().setSystemTypeMaterialColor(this.listPipingSystemType[i], this.doc, revirColor, this.isCreateFilter, this.listPipingSystemType[i].LinePatternId, this.listPipingSystemType[i].LineWeight);
			}
		}

		private void DrawDuct(int i, DataGridViewRow dr)
		{
			this.listMechanicalSystemType[i].Name = dr.Cells[0].Value.ToString();
			this.listMechanicalSystemType[i].get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(dr.Cells[1].Value.ToString());
			if (dr.Cells[3].Value != null && dr.Cells[3].Value.ToString() != "默认")
			{
				this.listMechanicalSystemType[i].LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, dr.Cells[3].Value.ToString()).Id;
			}
			else
			{
				this.listMechanicalSystemType[i].LinePatternId = ElementId.InvalidElementId;
			}
			if (dr.Cells[4].Value.ToString() != "默认")
			{
				this.listMechanicalSystemType[i].LineWeight = int.Parse(dr.Cells[4].Value.ToString());
			}
			else
			{
				this.listMechanicalSystemType[i].LineWeight = 5;
			}
			if (dr.Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(dr.Cells[2].Value.ToString());
				this.listMechanicalSystemType[i].LineColor = revirColor;
				new AssistSystemType().setSystemTypeMaterialColor(this.listMechanicalSystemType[i], this.doc, revirColor, this.isCreateFilter, this.listMechanicalSystemType[i].LinePatternId, this.listMechanicalSystemType[i].LineWeight);
			}
		}

		private void NewDrawPipe(int i, PipingSystemType pst, DataGridViewRow dr)
		{
			if (dr.Cells[3].Value != null && dr.Cells[3].Value.ToString() != "默认")
			{
				pst.LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, dr.Cells[3].Value.ToString()).Id;
			}
			else
			{
				pst.LinePatternId = ElementId.InvalidElementId;
			}
			if (dr.Cells[4].Value.ToString() != "默认")
			{
				pst.LineWeight = int.Parse(dr.Cells[4].Value.ToString());
			}
			else
			{
				pst.LineWeight = 5;
			}
			if (dr.Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(dr.Cells[2].Value.ToString());
				pst.LineColor = revirColor;
				new AssistSystemType().setSystemTypeMaterialColor(pst, this.doc, revirColor, this.isCreateFilter, pst.LinePatternId, pst.LineWeight);
			}
		}

		private void NewDrawDuct(int i, MechanicalSystemType mst, DataGridViewRow dr)
		{
			if (dr.Cells[3].Value != null && dr.Cells[3].Value.ToString() != "默认")
			{
				mst.LinePatternId = LinePatternElement.GetLinePatternElementByName(this.doc, dr.Cells[3].Value.ToString()).Id;
			}
			else
			{
				mst.LinePatternId = ElementId.InvalidElementId;
			}
			if (dr.Cells[4].Value.ToString() != "默认")
			{
				mst.LineWeight = int.Parse(dr.Cells[4].Value.ToString());
			}
			else
			{
				mst.LineWeight = 5;
			}
			if (dr.Cells[2].Value.ToString() != "默认")
			{
				Autodesk.Revit.DB.Color revirColor = SystemManageHelper.getRevirColor(dr.Cells[2].Value.ToString());
				mst.LineColor = revirColor;
				new AssistSystemType().setSystemTypeMaterialColor(mst, this.doc, revirColor, this.isCreateFilter, mst.LinePatternId, mst.LineWeight);
			}
		}

		private void buttonOK_Click(object sender, EventArgs e)
		{
			if (this.isCreateFilter)
			{
				foreach (Element element in new FilteredElementCollector(this.doc).OfCategory(BuiltInCategory.OST_Materials).ToElements().ToList<Element>())
				{
					Material material = element as Material;
					if (material.Name.Contains("HY"))
					{
						this.doc.Delete(material.Id);
					}
				}
				foreach (Element element2 in new FilteredElementCollector(this.doc).OfClass(typeof(ParameterFilterElement)).ToElements().ToList<Element>())
				{
					ParameterFilterElement parameterFilterElement = (ParameterFilterElement)element2;
					if (parameterFilterElement.Name.Contains("HY"))
					{
						this.doc.Delete(parameterFilterElement.Id);
					}
				}
			}
			DataGridView dtDuct = new DataGridView();
			DataGridView dtPipe = new DataGridView();
			this.InitlizedataGridView(ref dtDuct);
			this.InitlizedataGridView(ref dtPipe);
			this.DistinguishDuctPipe(ref dtDuct, ref dtPipe);
			for (int k = 0; k < this.listPipingSystemType.Count; k++)
			{
				if (k < dtPipe.RowCount - 1 && dtPipe.Rows[k] != null)
				{
					this.DrawPipe(k, dtPipe.Rows[k]);
				}
			}
			if (dtPipe.RowCount - 1 > this.listPipingSystemType.Count)
			{
				int i2;
				int i;
				for (i = this.listPipingSystemType.Count; i < dtPipe.RowCount - 1; i = i2 + 1)
				{
					systemTypeStruct systemTypeStruct = SystemTypeManageForm.structList.Find((systemTypeStruct p) => p.PipeSystemType == dtPipe.Rows[i].Cells[dtPipe.ColumnCount - 1].Value.ToString());
					if (systemTypeStruct != null)
					{
						MEPSystemClassification mepsystemClassification = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetPipeSystemTypeUS(systemTypeStruct.PipeSystemType), true);
						PipingSystemType pipingSystemType = PipingSystemType.Create(this.doc, mepsystemClassification, dtPipe.Rows[i].Cells[0].Value.ToString());
						pipingSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(dtPipe.Rows[i].Cells[1].Value.ToString());
						this.NewDrawPipe(i, pipingSystemType, dtPipe.Rows[i]);
					}
					i2 = i;
				}
			}
			for (int j = 0; j < this.listMechanicalSystemType.Count; j++)
			{
				if (j < dtDuct.RowCount - 1 && dtDuct.Rows[j] != null)
				{
					this.DrawDuct(j, dtDuct.Rows[j]);
				}
			}
			if (dtDuct.RowCount - 1 > this.listMechanicalSystemType.Count)
			{
				int i2;
				int i;
				for (i = this.listMechanicalSystemType.Count; i < dtDuct.RowCount - 1; i = i2 + 1)
				{
					systemTypeStruct systemTypeStruct2 = SystemTypeManageForm.structList.Find((systemTypeStruct p) => p.PipeSystemType == dtDuct.Rows[i].Cells[dtDuct.ColumnCount - 1].Value.ToString());
					if (systemTypeStruct2 != null)
					{
						MEPSystemClassification mepsystemClassification2 = (MEPSystemClassification)Enum.Parse(typeof(MEPSystemClassification), AssistSystemType.GetDuctSystemTypeUS(systemTypeStruct2.PipeSystemType), true);
						MechanicalSystemType mechanicalSystemType = MechanicalSystemType.Create(this.doc, mepsystemClassification2, dtDuct.Rows[i].Cells[0].Value.ToString());
						mechanicalSystemType.get_Parameter(BuiltInParameter.RBS_SYSTEM_ABBREVIATION_PARAM).Set(dtDuct.Rows[i].Cells[1].Value.ToString());
						this.NewDrawDuct(i, mechanicalSystemType, dtDuct.Rows[i]);
					}
					i2 = i;
				}
			}
			this.doc.Regenerate();
			foreach (PipingSystemType pipingSystemType2 in this.Get_PipingSystemType(this.doc))
			{
				if (pipingSystemType2.Name.Contains(" "))
				{
					pipingSystemType2.Name = pipingSystemType2.Name.Substring(0, pipingSystemType2.Name.IndexOf(' '));
				}
			}
			foreach (MechanicalSystemType mechanicalSystemType2 in this.Get_MechanicalSystemType(this.doc))
			{
				if (mechanicalSystemType2.Name.Contains(" "))
				{
					mechanicalSystemType2.Name = mechanicalSystemType2.Name.Substring(0, mechanicalSystemType2.Name.IndexOf(' '));
				}
			}
			this.WritePipingSystem();
			SystemTypeManageForm.structList.Clear();
			SystemTypeManageForm.bigList.Clear();
			SystemTypeManageForm.structListMoRen.Clear();
			base.Close();
			base.DialogResult = DialogResult.OK;
		}

		private void WritePipingSystem()
		{
			foreach (bigStruct bigStruct in SystemTypeManageForm.bigList)
			{
				if (bigStruct.style == this.listBox1.SelectedItem.ToString())
				{
					new SystemManageHelper().SaveBigList(bigStruct);
				}
				if (bigStruct.style == "当前样式")
				{
					new SystemManageHelper().SaveBigList(bigStruct);
				}
			}
			if (SystemTypeManageForm.bigList.Count > 0)
			{
				XML.deleteNext(SystemTypeManageForm.path, "systemTypeManage", this.startupType, "");
			}
			foreach (bigStruct bigStruct2 in SystemTypeManageForm.bigList)
			{
				List<systemTypeStruct> list = new List<systemTypeStruct>();
				if (bigStruct2.DuctSystemStruct != null)
				{
					list.AddRange(bigStruct2.DuctSystemStruct);
				}
				if (bigStruct2.PipeSystemStruct != null)
				{
					list.AddRange(bigStruct2.PipeSystemStruct);
				}
				XML.writeInfoToXML(SystemTypeManageForm.path, bigStruct2.style, "systemTypeManage", list, this.startupType);
			}
		}

		private void DistinguishDuctPipe(ref DataGridView dtDuct, ref DataGridView dtPipe)
		{
			for (int i = 0; i < this.dataGridView1.RowCount; i++)
			{
				object[] values = new object[]
				{
					this.dataGridView1.Rows[i].Cells[0].Value.ToString(),
					this.dataGridView1.Rows[i].Cells[1].Value.ToString(),
					this.dataGridView1.Rows[i].Cells[2].Value.ToString(),
					this.ifDocHasThisLinePattenElement(this.dataGridView1.Rows[i].Cells[3].Value.ToString()),
					this.dataGridView1.Rows[i].Cells[4].Value.ToString(),
					this.dataGridView1.Rows[i].Cells[5].Value.ToString(),
					this.dataGridView1.Rows[i].Cells[6].Value.ToString()
				};
				if (this.dataGridView1.Rows[i].Cells[this.dataGridView1.ColumnCount - 2].Value.ToString() == "风管系统")
				{
					dtDuct.Rows.Add(values);
				}
				else if (this.dataGridView1.Rows[i].Cells[this.dataGridView1.ColumnCount - 2].Value.ToString() == "管道系统")
				{
					dtPipe.Rows.Add(values);
				}
			}
		}

		private void buttonESC_Click(object sender, EventArgs e)
		{
			base.Close();
			SystemTypeManageForm.structList.Clear();
			SystemTypeManageForm.bigList.Clear();
			SystemTypeManageForm.structListMoRen.Clear();
		}

		private bool isNEWORCorrectFormShow()
		{
			bool result = false;
			if (this.treeView1.SelectedNode != null && this.treeView1.SelectedNode.Level == 2)
			{
				result = true;
			}
			return result;
		}

		private bool isNEWORCReateFormShow()
		{
			bool result = false;
			if (this.treeView1.SelectedNode != null && this.treeView1.SelectedNode.Level != 0)
			{
				result = true;
			}
			return result;
		}

		private void buttonNewSystem_Click(object sender, EventArgs e)
		{
			TreeNode selectedNode = this.treeView1.SelectedNode;
			SystemSetUpdateForm systemSetUpdateForm = new SystemSetUpdateForm(this.doc, SystemManageHelper.Get_LinePatternElement(this.doc), this.dataGridView1, this.listPipingSystemType, this.listMechanicalSystemType, this.treeView1, this.nowSelectedSystemCLass);
			if (this.isNEWORCReateFormShow())
			{
				systemSetUpdateForm.ShowDialog();
			}
			this.ColorInint();
			this.treeView1.SelectedNode = selectedNode;
		}

		private void setVisible(string compare, bool isTreeView)
		{
			if (this.treeView1.SelectedNode != null && this.treeView1.SelectedNode.Level != 0 && (this.treeView1.SelectedNode.Text == compare || this.treeView1.SelectedNode.Parent.Text == compare))
			{
				for (int i = 0; i < this.dataGridView1.RowCount; i++)
				{
					if (SystemTypeManageForm.structList[i].PipeSystemType != compare)
					{
						this.dataGridView1.Rows[i].Visible = false;
					}
					else
					{
						this.dataGridView1.Rows[i].Visible = true;
					}
					if (this.treeView1.SelectedNode.Nodes.Count < 1 && this.dataGridView1.Rows[i].Cells[0].Value.ToString() == this.treeView1.SelectedNode.Text)
					{
						this.dataGridView1.Rows[i].Selected = true;
					}
				}
			}
		}

		private int setVisible(string compare)
		{
			int result = 0;
			bool flag = true;
			if (this.treeView1.SelectedNode != null)
			{
				for (int i = 0; i < this.dataGridView1.RowCount; i++)
				{
					if (AssistSystemType.GetSystemTypeCH(SystemTypeManageForm.structList[i].PipeSystemType) == compare)
					{
						if (flag)
						{
							result = i;
						}
						this.dataGridView1.Rows[i].Visible = true;
						flag = false;
					}
				}
			}
			return result;
		}

		private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
		{
			foreach (TreeNode tnnn in this.GetAllTreeNodes(this.tn0))
			{
				this.treeview1BackColor(tnnn);
			}
            this.treeView1.SelectedNode.ForeColor = System.Drawing.Color.White;
            this.treeView1.SelectedNode.BackColor = System.Drawing.Color.DodgerBlue;
			for (int i = 0; i < this.dataGridView1.RowCount; i++)
			{
				this.dataGridView1.Rows[i].Visible = false;
			}
			List<TreeNode> allNoChildTreeNodes = this.GetAllNoChildTreeNodes(this.treeView1.SelectedNode);
			int num = int.MaxValue;
			foreach (TreeNode treeNode in allNoChildTreeNodes)
			{
				int num2 = this.setVisible(treeNode.Text);
				if (num > num2)
				{
					num = num2;
				}
			}
			if (this.dataGridView1.Rows.Count > 1)
			{
				this.dataGridView1.Rows[num].Selected = true;
			}
			if (this.treeView1.SelectedNode.Level == 2)
			{
				this.buttonCorrect.Enabled = false;
				this.buttonDelete.Enabled = true;
				this.buttonNewSystem.Enabled = true;
				this.nowSelectedSystemCLass = this.treeView1.SelectedNode.Parent.Text;
			}
			else if (this.treeView1.SelectedNode.Level == 1)
			{
				this.buttonCorrect.Enabled = false;
				this.buttonDelete.Enabled = false;
				this.buttonNewSystem.Enabled = true;
				this.treeView1.SelectedNode.Expand();
				this.nowSelectedSystemCLass = this.treeView1.SelectedNode.Text;
			}
			else
			{
				this.buttonCorrect.Enabled = false;
				this.buttonDelete.Enabled = false;
				this.buttonNewSystem.Enabled = false;
				this.treeView1.SelectedNode.Expand();
			}
			this.type = this.treeView1.SelectedNode.Text;
		}

		private TreeNode FindNodeByCode(TreeNodeCollection nodes, string Code)
		{
			if (nodes.Count == 0)
			{
				return null;
			}
			foreach (object obj in nodes)
			{
				TreeNode treeNode = (TreeNode)obj;
				if (treeNode.Text.ToString() == Code.Trim())
				{
					return treeNode;
				}
				TreeNode treeNode2;
				if (treeNode.Nodes.Count != 0)
				{
					treeNode2 = this.FindNodeByCode(treeNode.Nodes, Code);
				}
				else
				{
					treeNode2 = null;
				}
				if (treeNode2 != null)
				{
					return treeNode2;
				}
			}
			return null;
		}

		private void buttonDelete_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.SelectedRows.Count > 0)
			{
				int index = this.dataGridView1.SelectedRows[0].Index;
				if (index < this.listPipingSystemType.Count)
				{
					try
					{
						ICollection<ElementId> collection = this.doc.Delete(this.listPipingSystemType[index].Id);
						this.doc.Regenerate();
						if (collection != null && collection.Count > 0)
						{
							TreeNode treeNode = this.FindNodeByCode(this.treeView1.Nodes, SystemTypeManageForm.structList.ElementAt(index).PipingSystemType);
							SystemTypeManageForm.structList.RemoveAt(index);
							this.dataGridView1.Rows.RemoveAt(index);
							if (treeNode != null)
							{
								TreeNode selectedNode;
								if (treeNode.NextNode != null)
								{
									selectedNode = treeNode.NextNode;
								}
								else if (treeNode.PrevNode != null)
								{
									selectedNode = treeNode.PrevNode;
								}
								else
								{
									selectedNode = treeNode.Parent;
								}
								this.treeView1.SelectedNode = selectedNode;
								treeNode.Remove();
							}
							this.listPipingSystemType.RemoveAt(index);
						}
						else
						{
							MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						return;
					}
					catch
					{
						MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						return;
					}
				}
				if (index >= this.listPipingSystemType.Count && index < this.listPipingSystemType.Count + this.listMechanicalSystemType.Count)
				{
					try
					{
						ICollection<ElementId> collection2 = this.doc.Delete(this.listMechanicalSystemType[index - this.listPipingSystemType.Count].Id);
						this.doc.Regenerate();
						if (collection2 != null && collection2.Count > 0)
						{
							TreeNode treeNode2 = this.FindNodeByCode(this.treeView1.Nodes, SystemTypeManageForm.structList.ElementAt(index).PipingSystemType);
							SystemTypeManageForm.structList.RemoveAt(index);
							this.dataGridView1.Rows.RemoveAt(index);
							this.listMechanicalSystemType.RemoveAt(index - this.listPipingSystemType.Count);
							if (treeNode2 != null)
							{
								TreeNode selectedNode2;
								if (treeNode2.NextNode != null)
								{
									selectedNode2 = treeNode2.NextNode;
								}
								else if (treeNode2.PrevNode != null)
								{
									selectedNode2 = treeNode2.PrevNode;
								}
								else
								{
									selectedNode2 = treeNode2.Parent;
								}
								this.treeView1.SelectedNode = selectedNode2;
								treeNode2.Remove();
							}
						}
						else
						{
							MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						return;
					}
					catch
					{
						MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						return;
					}
				}
				if (index >= this.listPipingSystemType.Count + this.listMechanicalSystemType.Count)
				{
					TreeNode treeNode3 = this.FindNodeByCode(this.treeView1.Nodes, SystemTypeManageForm.structList.ElementAt(index).PipingSystemType);
					SystemTypeManageForm.structList.RemoveAt(index);
					this.dataGridView1.Rows.RemoveAt(index);
					if (treeNode3 != null)
					{
						TreeNode selectedNode3;
						if (treeNode3.NextNode != null)
						{
							selectedNode3 = treeNode3.NextNode;
						}
						else if (treeNode3.PrevNode != null)
						{
							selectedNode3 = treeNode3.PrevNode;
						}
						else
						{
							selectedNode3 = treeNode3.Parent;
						}
						this.treeView1.SelectedNode = selectedNode3;
						treeNode3.Remove();
						return;
					}
				}
			}
			else
			{
				MessageBox.Show("请先选择一个要删除的系统类型");
			}
		}

		private bool isLastPipeSystemClass(string name)
		{
			bool result = false;
			for (int i = 0; i < SystemTypeManageForm.structList.Count; i++)
			{
				if (SystemTypeManageForm.structList.ElementAt(i).PipingSystemType == name)
				{
					for (int j = 0; j < SystemTypeManageForm.structList.Count; j++)
					{
						if (SystemTypeManageForm.structList.ElementAt(i).PipeSystemType == SystemTypeManageForm.structList.ElementAt(j).PipeSystemType && i != j)
						{
							result = true;
						}
					}
				}
			}
			return result;
		}

		private void SystemTypeManageForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.WritePipingSystem();
			SystemTypeManageForm.structList.Clear();
			SystemTypeManageForm.bigList.Clear();
			SystemTypeManageForm.structListMoRen.Clear();
		}

		private void button1_Click_1(object sender, EventArgs e)
		{
			if (this.listBox1.SelectedItem != null)
			{
				new AddStyle(this.listBox1, "复制").ShowDialog();
			}
		}

		private void button2_Click(object sender, EventArgs e)
		{
			int selectedIndex = this.listBox1.SelectedIndex;
			if (this.listBox1.SelectedItem != null && this.listBox1.SelectedItem.ToString() != "当前样式" && this.listBox1.SelectedItem.ToString() != "盈建科样式")
			{
				new AddStyle(this.listBox1, "修改", this.dataGridView1, selectedIndex)
				{
					Text = "修改"
				}.ShowDialog();
				return;
			}
			YJKMessageBox.Show("当前样式名称不得修改！");
		}

		private void button3_Click(object sender, EventArgs e)
		{
			int selectedIndex = this.listBox1.SelectedIndex;
			if (this.listBox1.SelectedItem != null && this.listBox1.SelectedItem.ToString() != "当前样式" && this.listBox1.SelectedItem.ToString() != "盈建科样式")
			{
				if (MessageBox.Show("是否删除" + this.listBox1.SelectedItem.ToString() + "?", "操作提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					for (int i = 0; i < SystemTypeManageForm.bigList.Count; i++)
					{
						if (this.listBox1.SelectedItem.ToString() == SystemTypeManageForm.bigList.ElementAt(i).style)
						{
							SystemTypeManageForm.bigList.RemoveAt(i);
							XML.deleteNext(SystemTypeManageForm.path, "systemTypeManage", this.startupType, this.listBox1.SelectedItem.ToString());
							break;
						}
					}
					this.listBox1.SelectedItem = "当前样式";
					this.listBox1.Items.RemoveAt(selectedIndex);
					this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
					return;
				}
			}
			else
			{
				YJKMessageBox.Show("请确保先选择一个样式再删除，并且当前样式不得删除！");
			}
		}

		private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.listBox1.SelectedItem != null && this.listBox1.SelectedItem.ToString() != "当前样式" && this.listBox1.SelectedItem.ToString() != "盈建科样式")
			{
				this.button2.Enabled = true;
				this.button3.Enabled = true;
			}
			else
			{
				this.button2.Enabled = false;
				this.button3.Enabled = false;
			}
			if (this.listBox1.SelectedItem != null)
			{
				this.button1.Enabled = true;
			}
			else
			{
				this.button1.Enabled = false;
			}
			this.isValid = false;
			foreach (bigStruct bigStruct in SystemTypeManageForm.bigList)
			{
				if (bigStruct.style == SystemTypeManageForm.systemFirstStyle && this.isUpdateBsStyle)
				{
					SystemTypeManageForm.bigList.Remove(bigStruct);
					SystemManageHelper systemManageHelper = new SystemManageHelper();
					bigStruct bigStruct2 = new bigStruct();
					bigStruct2.style = SystemTypeManageForm.systemFirstStyle;
					systemManageHelper.SaveBigList(bigStruct2);
					SystemTypeManageForm.bigList.Add(bigStruct2);
					break;
				}
			}
			foreach (bigStruct bigStruct3 in SystemTypeManageForm.bigList)
			{
				if (bigStruct3.style == this.listBox1.SelectedItem.ToString())
				{
					SystemTypeManageForm.structList.Clear();
					this.dataGridView1.Rows.Clear();
					List<systemTypeStruct> list = new List<systemTypeStruct>();
					list.AddRange(bigStruct3.DuctSystemStruct);
					list.AddRange(bigStruct3.PipeSystemStruct);
					int count = this.dataGridView1.Rows.Count;
					int count2 = list.Count;
					List<systemTypeStruct> list2 = new List<systemTypeStruct>();
					for (int i = 0; i < count2; i++)
					{
						for (int j = 0; j < count; j++)
						{
							if (list[i].PipingSystemType == SystemTypeManageForm.structList[j].PipingSystemType)
							{
								this.dataGridView1.Rows[j].Cells[1].Value = list[i].PipingSystemTypeAbb;
								this.dataGridView1.Rows[j].Cells[2].Value = list[i].Color;
								this.dataGridView1.Rows[j].Cells[3].Value = this.ifDocHasThisLinePattenElement(list[i].LinePattern);
								this.dataGridView1.Rows[j].Cells[4].Value = list[i].LineWeight;
								this.dataGridView1.Rows[j].Cells[5].Value = list[i].SystemClass;
								this.dataGridView1.Rows[j].Cells[5].Value = list[i].PipeSystemType;
								list2.Add(list[i]);
								SystemTypeManageForm.structList.ElementAt(j).PipingSystemTypeAbb = list[i].PipingSystemTypeAbb;
								SystemTypeManageForm.structList.ElementAt(j).Color = list[i].Color;
								SystemTypeManageForm.structList.ElementAt(j).LinePattern = this.ifDocHasThisLinePattenElement(list[i].LinePattern);
								SystemTypeManageForm.structList.ElementAt(j).LineWeight = list[i].LineWeight;
							}
						}
					}
					if (list.Count > 0)
					{
						foreach (systemTypeStruct systemTypeStruct in list)
						{
							if (!list2.Contains(systemTypeStruct))
							{
								object[] values = new object[]
								{
									systemTypeStruct.PipingSystemType,
									systemTypeStruct.PipingSystemTypeAbb,
									systemTypeStruct.Color,
									this.ifDocHasThisLinePattenElement(systemTypeStruct.LinePattern),
									systemTypeStruct.LineWeight,
									systemTypeStruct.SystemClass,
									systemTypeStruct.PipeSystemType
								};
								this.dataGridView1.Rows.Add(values);
								SystemTypeManageForm.structList.Add(systemTypeStruct);
							}
						}
					}
				}
			}
			SystemTypeManageForm.systemFirstStyle = this.listBox1.SelectedItem.ToString();
			this.isValid = true;
			this.ColorInint();
			List<TreeNode> allTreeNodes = this.GetAllTreeNodes(this.tn0);
			for (int k = 0; k < allTreeNodes.Count; k++)
			{
				if (this.type == allTreeNodes[k].Text)
				{
					this.treeView1.SelectedNode = allTreeNodes[0];
					this.treeView1.SelectedNode = allTreeNodes[k];
					break;
				}
			}
			if (this.dataGridView1.RowCount > 1)
			{
				this.buttonOK.Enabled = true;
				return;
			}
			this.buttonOK.Enabled = false;
		}

		private string ifDocHasThisLinePattenElement(string linePattenName)
		{
			string result = "默认";
			using (List<LinePatternElement>.Enumerator enumerator = this.linePattern.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.Name == linePattenName)
					{
						result = linePattenName;
						break;
					}
				}
			}
			return result;
		}

		private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
		{
			if (this.isValid)
			{
				new Regex("^[a-zA-Z0-9_\\u4e00-\\u9fa5\\' ']+$");
				Regex regex = new Regex("\\S");
				AssistSystemType assistSystemType = new AssistSystemType();
				if (e.ColumnIndex == 0)
				{
					if (assistSystemType.JudgeNameContainTeShu(e.FormattedValue.ToString().Trim()) || !regex.IsMatch(e.FormattedValue.ToString().Trim()))
					{
						YJKMessageBox.Show("系统名称不能为空,并且不能包含下列任一字符：\\:{}[]|;<>?`~！");
						e.Cancel = true;
						this.dataGridView1.CancelEdit();
					}
					else
					{
						e.Cancel = false;
					}
				}
				int rowIndex = e.RowIndex;
				for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
				{
					if (e.FormattedValue.ToString().Trim() == this.dataGridView1.Rows[i].Cells[0].Value.ToString() && e.RowIndex != i)
					{
						YJKMessageBox.Show("该系统类型名字在系统中已存在，请更换一个名字！");
						e.Cancel = true;
						this.dataGridView1.CancelEdit();
						return;
					}
				}
			}
		}

		private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
		{
			int rowIndex = e.RowIndex;
			if (e.ColumnIndex == 0)
			{
				this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString().Trim();
			}
			else if (e.ColumnIndex == 1)
			{
				if (this.dataGridView1.Rows[e.RowIndex].Cells[1].Value != null)
				{
					this.dataGridView1.Rows[e.RowIndex].Cells[1].Value = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString().Trim();
					SystemTypeManageForm.structList.ElementAt(rowIndex).PipingSystemTypeAbb = this.dataGridView1.Rows[rowIndex].Cells[1].Value.ToString();
				}
				else
				{
					this.dataGridView1.Rows[e.RowIndex].Cells[1].Value = "";
					SystemTypeManageForm.structList.ElementAt(rowIndex).PipingSystemTypeAbb = "";
				}
			}
			SystemTypeManageForm.structList.ElementAt(rowIndex).PipingSystemType = this.dataGridView1.Rows[rowIndex].Cells[0].Value.ToString();
			SystemTypeManageForm.structList.ElementAt(rowIndex).Color = this.dataGridView1.Rows[rowIndex].Cells[2].Value.ToString();
			SystemTypeManageForm.structList.ElementAt(rowIndex).LinePattern = this.dataGridView1.Rows[rowIndex].Cells[3].Value.ToString();
			SystemTypeManageForm.structList.ElementAt(rowIndex).LineWeight = this.dataGridView1.Rows[rowIndex].Cells[4].Value.ToString();
		}

		private void button1_MouseEnter(object sender, EventArgs e)
		{
			new ToolTip
			{
				ShowAlways = true
			}.SetToolTip(this.button1, "复制样式");
		}

		private void button2_MouseEnter(object sender, EventArgs e)
		{
			new ToolTip
			{
				ShowAlways = true
			}.SetToolTip(this.button2, "编辑样式");
		}

		private void button3_MouseEnter(object sender, EventArgs e)
		{
			new ToolTip
			{
				ShowAlways = true
			}.SetToolTip(this.button3, "删除样式");
		}

		private void buttonCorrect_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.SelectedRows.Count > 0)
			{
				int index = this.dataGridView1.SelectedRows[0].Index;
				new SystemSetUpdateForm(this.doc, SystemManageHelper.Get_LinePatternElement(this.doc), this.dataGridView1, this.listPipingSystemType, this.listMechanicalSystemType, this.treeView1, this.nowSelectedSystemCLass, index).ShowDialog();
				this.ColorInint();
				return;
			}
			YJKMessageBox.Show("请先选择要修改的系统类型！");
		}

		private void ColorInint()
		{
			int count = this.dataGridView1.Rows.Count;
			for (int i = 0; i < count; i++)
			{
				if (this.dataGridView1[2, i].Value != null)
				{
                    System.Drawing.Color xmldataColor = SystemManageHelper.getXMLDataColor(this.dataGridView1[2, i].Value.ToString());
					this.dataGridView1[2, i].Style.ForeColor = xmldataColor;
					this.dataGridView1[2, i].ReadOnly = true;
				}
			}
		}

		private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (e.ColumnIndex == 2 && e.RowIndex >= 0)
			{
				ColorDialog colorDialog = new ColorDialog();
				colorDialog.AllowFullOpen = true;
				colorDialog.FullOpen = true;
                System.Drawing.Color xmldataColor = SystemManageHelper.getXMLDataColor(this.dataGridView1[2, e.RowIndex].Value.ToString());
				if (!xmldataColor.IsKnownColor)
				{
					int[] array = new int[16];
					array[0] = SystemManageHelper.GetIntAboutColor(xmldataColor);
					colorDialog.CustomColors = array;
				}
				colorDialog.Color = xmldataColor;
				DialogResult dialogResult = colorDialog.ShowDialog();
				if (DialogResult.OK == dialogResult)
				{
					string newRGB = SystemManageHelper.getNewRGB(colorDialog.Color.R);
					string newRGB2 = SystemManageHelper.getNewRGB(colorDialog.Color.G);
					string newRGB3 = SystemManageHelper.getNewRGB(colorDialog.Color.B);
					string str = string.Concat(new string[]
					{
						"RGB ",
						newRGB.ToString(),
						" ",
						newRGB2.ToString(),
						" ",
						newRGB3.ToString()
					});
					this.dataGridView1[2, e.RowIndex].Value = "█" + str;
					this.dataGridView1[2, e.RowIndex].Style.ForeColor = colorDialog.Color;
					this.dataGridView1[2, e.RowIndex].ReadOnly = true;
				}
			}
		}

		private void dataGridView1_SelectionChanged(object sender, EventArgs e)
		{
		}

		private void treeview1BackColor(TreeNode tnnn)
		{
            tnnn.BackColor = System.Drawing.Color.White;
            tnnn.ForeColor = System.Drawing.Color.Black;
			foreach (object obj in tnnn.Nodes)
			{
				TreeNode treeNode = (TreeNode)obj;
                treeNode.BackColor = System.Drawing.Color.White;
                treeNode.ForeColor = System.Drawing.Color.Black;
			}
		}

		private void buttonNewSystem_MouseEnter(object sender, EventArgs e)
		{
			new ToolTip
			{
				ShowAlways = true
			}.SetToolTip(this.buttonNewSystem, "新建类型");
		}

		private void buttonCorrect_MouseEnter(object sender, EventArgs e)
		{
			new ToolTip
			{
				ShowAlways = true
			}.SetToolTip(this.buttonCorrect, "编辑类型");
		}

		private void buttonDelete_MouseEnter(object sender, EventArgs e)
		{
			new ToolTip
			{
				ShowAlways = true
			}.SetToolTip(this.buttonDelete, "删除类型");
		}

		private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right && e.RowIndex >= 0)
			{
				if (!this.dataGridView1.Rows[e.RowIndex].Selected)
				{
					this.dataGridView1.ClearSelection();
					this.dataGridView1.Rows[e.RowIndex].Selected = true;
				}
				if (this.dataGridView1.SelectedRows.Count == 1)
				{
					this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
				}
				this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ContextMenuStrip = this.contextMenuStrip1;
                this.contextMenuStrip1.Show(System.Windows.Forms.Control.MousePosition.X, System.Windows.Forms.Control.MousePosition.Y);
			}
		}

		private void cmsUpdate_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.SelectedRows.Count > 0)
			{
				int index = this.dataGridView1.SelectedRows[0].Index;
				new SystemSetUpdateForm(this.doc, SystemManageHelper.Get_LinePatternElement(this.doc), this.dataGridView1, this.listPipingSystemType, this.listMechanicalSystemType, this.treeView1, this.nowSelectedSystemCLass, index).ShowDialog();
				this.ColorInint();
				return;
			}
			YJKMessageBox.Show("请先选择要修改的系统类型！");
		}

		private void cmsCreate_Click(object sender, EventArgs e)
		{
			if (this.isNEWORCReateFormShow() || this.dataGridView1.SelectedRows.Count > 0)
			{
				int index = this.dataGridView1.SelectedRows[0].Index;
				this.nowSelectedSystemCLass = SystemTypeManageForm.structList.ElementAt(index).SystemClass;
				new SystemSetUpdateForm(this.doc, SystemManageHelper.Get_LinePatternElement(this.doc), this.dataGridView1, this.listPipingSystemType, this.listMechanicalSystemType, this.treeView1, this.nowSelectedSystemCLass).ShowDialog();
			}
			this.ColorInint();
		}

		private void cmsDelete_Click(object sender, EventArgs e)
		{
			if (this.dataGridView1.SelectedRows.Count > 0)
			{
				int index = this.dataGridView1.SelectedRows[0].Index;
				if (index < this.listPipingSystemType.Count)
				{
					try
					{
						ICollection<ElementId> collection = this.doc.Delete(this.listPipingSystemType[index].Id);
						this.doc.Regenerate();
						if (collection != null && collection.Count > 0)
						{
							TreeNode treeNode = this.FindNodeByCode(this.treeView1.Nodes, SystemTypeManageForm.structList.ElementAt(index).PipingSystemType);
							SystemTypeManageForm.structList.RemoveAt(index);
							this.dataGridView1.Rows.RemoveAt(index);
							if (treeNode != null)
							{
								TreeNode selectedNode;
								if (treeNode.NextNode != null)
								{
									selectedNode = treeNode.NextNode;
								}
								else if (treeNode.PrevNode != null)
								{
									selectedNode = treeNode.PrevNode;
								}
								else
								{
									selectedNode = treeNode.Parent;
								}
								this.treeView1.SelectedNode = selectedNode;
								treeNode.Remove();
							}
							this.listPipingSystemType.RemoveAt(index);
						}
						else
						{
							MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						return;
					}
					catch
					{
						MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						return;
					}
				}
				if (index >= this.listPipingSystemType.Count && index < this.listPipingSystemType.Count + this.listMechanicalSystemType.Count)
				{
					try
					{
						ICollection<ElementId> collection2 = this.doc.Delete(this.listMechanicalSystemType[index - this.listPipingSystemType.Count].Id);
						this.doc.Regenerate();
						if (collection2 != null && collection2.Count > 0)
						{
							TreeNode treeNode2 = this.FindNodeByCode(this.treeView1.Nodes, SystemTypeManageForm.structList.ElementAt(index).PipingSystemType);
							SystemTypeManageForm.structList.RemoveAt(index);
							this.dataGridView1.Rows.RemoveAt(index);
							this.listMechanicalSystemType.RemoveAt(index - this.listPipingSystemType.Count);
							if (treeNode2 != null)
							{
								TreeNode selectedNode2;
								if (treeNode2.NextNode != null)
								{
									selectedNode2 = treeNode2.NextNode;
								}
								else if (treeNode2.PrevNode != null)
								{
									selectedNode2 = treeNode2.PrevNode;
								}
								else
								{
									selectedNode2 = treeNode2.Parent;
								}
								this.treeView1.SelectedNode = selectedNode2;
								treeNode2.Remove();
							}
						}
						else
						{
							MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						}
						return;
					}
					catch
					{
						MessageBox.Show("每个系统分类的最后一个系统类型不能删除。或者该系统类型正在被使用", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
						return;
					}
				}
				if (index >= this.listPipingSystemType.Count + this.listMechanicalSystemType.Count)
				{
					TreeNode treeNode3 = this.FindNodeByCode(this.treeView1.Nodes, SystemTypeManageForm.structList.ElementAt(index).PipingSystemType);
					SystemTypeManageForm.structList.RemoveAt(index);
					this.dataGridView1.Rows.RemoveAt(index);
					if (treeNode3 != null)
					{
						TreeNode selectedNode3;
						if (treeNode3.NextNode != null)
						{
							selectedNode3 = treeNode3.NextNode;
						}
						else if (treeNode3.PrevNode != null)
						{
							selectedNode3 = treeNode3.PrevNode;
						}
						else
						{
							selectedNode3 = treeNode3.Parent;
						}
						this.treeView1.SelectedNode = selectedNode3;
						treeNode3.Remove();
						return;
					}
				}
			}
			else
			{
				MessageBox.Show("请先选择一个要删除的系统类型");
			}
		}

		private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
		{
			e.Control.ContextMenuStrip = this.contextMenuStrip1;
			if (e.Control is DataGridViewTextBoxEditingControl)
			{
                System.Windows.Forms.Control control = (DataGridViewTextBoxEditingControl)e.Control;
				ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
				contextMenuStrip = this.contextMenuStrip1;
				control.ContextMenuStrip = contextMenuStrip;
			}
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (!this.checkBox1.Checked)
			{
				this.isCreateFilter = false;
				return;
			}
			this.isCreateFilter = true;
		}

		private void treeView1_Leave(object sender, EventArgs e)
		{
		}

		private List<TreeNode> GetAllTreeNodes(TreeNode treeNode)
		{
			List<TreeNode> list = new List<TreeNode>();
			list.Add(treeNode);
			foreach (object obj in treeNode.Nodes)
			{
				TreeNode treeNode2 = (TreeNode)obj;
				list.AddRange(this.GetAllTreeNodes(treeNode2));
			}
			return list;
		}

		private List<TreeNode> GetAllNoChildTreeNodes(TreeNode treeNode)
		{
			List<TreeNode> list = new List<TreeNode>();
			if (treeNode.Nodes.Count == 0)
			{
				list.Add(treeNode);
			}
			else
			{
				foreach (object obj in treeNode.Nodes)
				{
					TreeNode treeNode2 = (TreeNode)obj;
					list.AddRange(this.GetAllNoChildTreeNodes(treeNode2));
				}
			}
			return list;
		}

		private void InitlizedataGridView(ref DataGridView dt)
		{
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn.HeaderText = "系统类型名称";
			dataGridViewTextBoxColumn.Width = 100;
			dataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			dt.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn
			});
			dataGridViewTextBoxColumn.MinimumWidth = 100;
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn2.HeaderText = "缩写";
			dataGridViewTextBoxColumn2.Width = 60;
			dataGridViewTextBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			dt.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn2
			});
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn3.HeaderText = "线颜色";
			dataGridViewTextBoxColumn3.Width = 125;
			dataGridViewTextBoxColumn3.SortMode = DataGridViewColumnSortMode.NotSortable;
			dt.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn3
			});
			dataGridViewTextBoxColumn3.ReadOnly = true;
			dataGridViewTextBoxColumn3.MinimumWidth = 125;
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn.HeaderText = "线型";
			dataGridViewComboBoxColumn.Width = 100;
			dataGridViewComboBoxColumn.SortMode = DataGridViewColumnSortMode.NotSortable;
			dt.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn
			});
			dataGridViewComboBoxColumn.FlatStyle = FlatStyle.Popup;
			DataGridViewComboBoxColumn dataGridViewComboBoxColumn2 = new DataGridViewComboBoxColumn();
			dataGridViewComboBoxColumn2.HeaderText = "线宽";
			dataGridViewComboBoxColumn2.Width = 56;
			dataGridViewComboBoxColumn2.SortMode = DataGridViewColumnSortMode.NotSortable;
			dt.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewComboBoxColumn2
			});
			dataGridViewComboBoxColumn2.FlatStyle = FlatStyle.Popup;
			foreach (LinePatternElement linePatternElement in SystemManageHelper.Get_LinePatternElement(this.doc))
			{
				dataGridViewComboBoxColumn.Items.AddRange(new object[]
				{
					linePatternElement.Name
				});
			}
			dataGridViewComboBoxColumn.Items.Add("默认");
			for (int i = 1; i < 17; i++)
			{
				dataGridViewComboBoxColumn2.Items.Add(i.ToString());
			}
			dataGridViewComboBoxColumn2.Items.Add("默认");
			dt.RowTemplate.Height = 22;
			dt.RowHeadersWidth = 30;
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn4 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn4.HeaderText = "类型";
			dataGridViewTextBoxColumn4.Width = 1;
			dataGridViewTextBoxColumn4.SortMode = DataGridViewColumnSortMode.NotSortable;
			dt.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn4
			});
			DataGridViewTextBoxColumn dataGridViewTextBoxColumn5 = new DataGridViewTextBoxColumn();
			dataGridViewTextBoxColumn5.HeaderText = "系统类型";
			dataGridViewTextBoxColumn5.Width = 1;
			dataGridViewTextBoxColumn5.SortMode = DataGridViewColumnSortMode.NotSortable;
			dt.Columns.AddRange(new DataGridViewColumn[]
			{
				dataGridViewTextBoxColumn5
			});
			dt.Columns[5].Visible = false;
			dt.Columns[6].Visible = false;
		}

		public List<PipingSystemType> Get_PipingSystemType(Document document)
		{
			IEnumerable<Element> enumerable = new FilteredElementCollector(document).OfClass(typeof(PipingSystemType)).ToElements();
			List<PipingSystemType> list = new List<PipingSystemType>();
			foreach (Element element in enumerable)
			{
				PipingSystemType item = element as PipingSystemType;
				list.Add(item);
			}
			return list;
		}

		public List<MechanicalSystemType> Get_MechanicalSystemType(Document document)
		{
			IEnumerable<Element> enumerable = new FilteredElementCollector(document).OfClass(typeof(MechanicalSystemType)).ToElements();
			List<MechanicalSystemType> list = new List<MechanicalSystemType>();
			foreach (Element element in enumerable)
			{
				MechanicalSystemType item = element as MechanicalSystemType;
				list.Add(item);
			}
			return list;
		}

		private List<PipingSystemType> listPipingSystemType = new List<PipingSystemType>();

		private List<MechanicalSystemType> listMechanicalSystemType = new List<MechanicalSystemType>();

		private Document doc;

		private UIApplication app;

		private UIDocument uidoc;

		private List<LinePatternElement> linePattern = new List<LinePatternElement>();

		private string nowSelectedSystemCLass = "所有专业分类";

		private string type = "";

		public static List<systemTypeStruct> structList = new List<systemTypeStruct>();

		public static List<bigStruct> bigList = new List<bigStruct>();

		public static List<systemTypeStruct> structListMoRen = new List<systemTypeStruct>();

		public static string path = Path.Combine(Product.UserDataLocation, "YJKPipingSystemTypeSetInformation.xml");

		private bool isValid;

		private TreeNode tn0 = new TreeNode("所有专业分类");

		private TreeNode tnduct = new TreeNode("风管系统");

		private TreeNode tnpipe = new TreeNode("管道系统");

		private bool isUpdateBsStyle;

		private int startupType;

		private int intImportExport = 1111;

		public bool isMoveNextItem;

		public static string systemFirstStyle = "当前样式";

		private bool isCreateFilter;
	}
}
